var rename = tool.getCookie('rename')
if(rename){
    $('#usname').val(rename)
}
$('.button').click(function(){
    if($('#usname').val() === ''){
        layer.msg('用户名不能为空',{
            icon:2,
            time:1500
        })
        return false;
    }
    if($('#usword').val() === ''){
        layer.msg('密码不能为空',{
            icon:2,
            time:1500
        })
        return false;
    }
    var loadindex = layer.load(0, {
        shade: [0.5,'#666'] //0.1透明度的白色背景
      })
    $.post('../php/login.php',{
        username:$('#usname').val(),
        password:$('#usword').val()
    },res=>{
        var {meta:{status,msg},data} = res;
        layer.close(loadindex)
        if(status===1){
            layer.msg(msg,{
                icon:1,
                time:1000
            },function(){
                // 添加cookie 
                tool.setCookie('username',$('#usname').val(),7200)
                // 判断是否记住用户名
                if($('input[type="checkbox"]').prop('checked')){
                    // 存cookie
                    tool.setCookie('rename',$('#usname').val(),3600*24*7)
                }
                var url=localStorage.getItem("url");
                if(url){
                    localStorage.removeItem("url")
                    location.href =url
                }else{
                    location.href = "../index.html"
                }
            })
        }else{
            layer.msg(msg,{
                icon:2,
                time:1500
            })
            return false;
        }
    },'json')
    return false;
})
$(".register").click(function(){
    location.href="../register.html"
    return false
})